package yx.action;

import org.apache.log4j.Logger;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.springframework.beans.factory.annotation.Autowired;

import yx.service.UserServiceInt;
import yx.vo.JsonVO;
import yx.vo.UserVO;

import com.opensymphony.xwork2.ModelDriven;

@ParentPackage("basePackage")
@Namespace("/")
@Action(value = "userAction")
public class UserAction extends BaseAction implements ModelDriven<UserVO> {
	/**
	 * Logger for this class
	 */
	private static final Logger logger = Logger.getLogger(UserAction.class);

	private UserVO user = new UserVO();

	@Override
	public UserVO getModel() {
		return user;
	}

	public void queryUser() {
		super.writeJson(userService.datagrid(user));
	}

	private UserServiceInt userService;

	public UserServiceInt getUserService() {
		return userService;
	}

	@Autowired
	public void setUserService(UserServiceInt userService) {
		this.userService = userService;
	}

	public void addUser() {
		JsonVO j = new JsonVO();
		try {
			UserVO u = userService.save(user);
			j.setSuccess(true);
			j.setMsg("增加成功！");
			j.setObj(u);
		} catch (Exception e) {
			j.setMsg(e.getMessage());
		}
		super.writeJson(j);
	}

	/**
	 * 编辑
	 */
	public void editUser() {
		UserVO u = userService.edit(user);
		JsonVO j = new JsonVO();
		j.setSuccess(true);
		j.setMsg("编辑成功！");
		j.setObj(u);
		super.writeJson(j);
	}

	/**
	 * 删除 用户
	 */
	public void removeUser() {
		userService.remove(user.getIds());
		JsonVO j = new JsonVO();
		j.setSuccess(true);
		j.setMsg("删除成功！");
		super.writeJson(j);
	}
	
	/**
     * 锁定 用户
     */
    public void lockingUser() {
        userService.lockingUser(user.getIds());
        JsonVO j = new JsonVO();
        j.setSuccess(true);
        j.setMsg("锁定成功！");
        super.writeJson(j);
    }
    
    /**
     * 激活 用户
     */
    public void activatingUser() {
        userService.activatingUser(user.getIds());
        JsonVO j = new JsonVO();
        j.setSuccess(true);
        j.setMsg("激活成功！");
        super.writeJson(j);
    }
    
    /**
     * 重置密码
     */
    public void resetPasswordUser() {
        userService.resetPasswordUser(user.getIds());
        JsonVO j = new JsonVO();
        j.setSuccess(true);
        j.setMsg("重置密码成功！");
        super.writeJson(j);
    }

}
